<template>
	<view class="my bigestBox">
		<view class="head boxSize_bb">
			<view class="head_content flex_jcsb">
				<image :src="avatar" mode="" class="head_left"></image>
				<view class="head_right flexDeCo">
					<view class="hr_top flex_jcsb"><text>{{nickname}}</text>
						<image src="/static/images/My/Setting.png" mode=""
							style="width: 40rpx;height: 40rpx; color:#FFFFFF" @click="goToUserCenterPage">
						</image>
					</view>
					<!-- <view class="hr_bottom">{{telephone ? maskPhoneNumber(telephone) : "未填写"}}</view> -->
					<view class="hr_bottom">(ID：{{ id }})</view>
				</view>
			</view>
			<view class="tabBar flex">
				<view class="tbContent flex_jcsb boxSize_bb" style="padding-left: 20rpx;padding-right: 20rpx;">
					<view class="tb1 flexDeCo tbItem" @click="goto('goToMyorder')"
						style="justify-content: center; align-items: center; text-align: center;">
						<image src="/static/images/My/MyOrders.png" mode="" class="tbImg"></image>
						<view class="tbText flex" style="white-space: nowrap;">全部订单</view>
					</view>
					<view class="tb2 flexDeCo tbItem" @click="goto('goToShoppingAddress')"
						style="justify-content: center; align-items: center; text-align: center;">
						<image src="/static/images/My/RecipientAddress.png" mode="" class="tbImg"></image>
						<view class="tbText flex" style="white-space: nowrap;">收货地址</view>
					</view>
					<view class="tb3 flexDeCo tbItem"
						style="justify-content: center; align-items: center; text-align: center; "
						@click="goto('goToPointsDetails')">
						<image src="/static/images/My/MyPoint.png" mode="" class="tbImg"></image>
						<view class="tbText flex" style="white-space: nowrap;">我的积分</view>
					</view>
					<view class="tb3 flexDeCo tbItem" @click="goto('gotoMycollection')"
						style="justify-content: center; align-items: center; text-align: center;">
						<image src="/static/images/My/myollection.png" mode="" class="tbImg"></image>
						<view class="tbText flex" style="white-space: nowrap;">我的收藏 </view>
					</view>
				</view>
			</view>
		</view>
		<view class="one flex_jcsb boxSize_bb item" v-if="showGotoAgency">
			<view class="one_left text">
				分享即得，永久有效
			</view>
			<view class="one_right button" @click="goto('goToAgency')">立即申请</view>
		</view>
		<view class="two flex_jcsb boxSize_bb item" v-if="showCommissionDetail"
			:style="!showGotoAgency ? 'margin-top: 136rpx;' : ''">
			<view class="two_left flex">
				<view class="tl_one text">我的分佣：&nbsp;</view>
				<view class="tl_two">{{ totalCommission }}元</view>
			</view>
			<view class="two_right button" @click="goToCommissionDetail">查看明细</view>
		</view>
		<view class="three flex_jcsb boxSize_bb item" @click="goto('gotToMyPartnerPage')">
			<view class="one_left text">
				我的搭子
			</view>
			<image src="/static/images/My/Collapse.png" mode="" style="width: 30rpx;height: 30rpx;"></image>
		</view>
		<view class="boxSize_bb four item" style="background-color: white; padding-left: 30rpx;padding-right: 30rpx;">
			<view :class="['flex_jcsb', 'boxSize_bb', index > 0 ? 'second-item' : '']"
				v-for="(item, index) in extraList" :key="index" @tap="navigateTo(item.url)">
				<view class="flex boxSize_bb">
					<image :src="item.imgUrl" mode="" style="width: 40rpx;height: 42rpx;"></image>
					<view class="tl_two" style="color: black; margin-left: 20rpx; font-size: 28rpx;">{{ item.text }}
					</view>
				</view>
				<image src="/static/images/My/Collapse.png" mode="" style="width: 30rpx;height: 30rpx;"></image>
			</view>
			<!-- <view class="flex_jcsb boxSize_bb" style="margin-top: 60rpx; font-size: 30rpx;">
				<view class="two_left flex">
					<image src="/static/images/My/UserAgreement.png" mode="" style="width: 40rpx;height: 40rpx;">
					</image>
					<view class="tl_two" style="color: black;margin-left: 20rpx;">用户协议</view>
				</view>
				<image src="/static/images/My/Collapse.png" mode="" style="width: 30rpx;height: 30rpx;"></image>
			</view>
			<view class="flex_jcsb boxSize_bb" style="margin-top: 60rpx;">
				<view class="two_left flex">
					<image src="/static/images/My/AboutUs.png" mode="" style="width: 40rpx;height: 40rpx;"></image>
					<view class="tl_two" style="color: black;margin-left: 20rpx;">关于我们</view>
				</view>
				<image src="/static/images/My/Collapse.png" mode="" style="width: 30rpx;height: 30rpx;"></image>
			</view> -->
		</view>
	</view>
</template>

<script>
	import {
		navigateTo
	} from '../../utils/promise';
	import {
		getCommissionTotal
	} from "../../api/commission"

	import {
		getAgentInfo
	} from '../../api/commission';

	export default {
		data() {
			return {
				phone: null,
				totalCommission: 0,
				extraList: [{
						text: "帮助中心",
						url: "/pages/HelpCenter/HelpCenter",
						imgUrl: "/static/images/My/HelpCenter.png",
					},
					{
						text: "用户协议",
						url: "/pages/UserAgreeMent/UserAgreeMent",
						imgUrl: "/static/images/My/UserAgreement.png",
					},
					{
						text: "关于我们",
						url: "/pages/AboutMe/AboutMe",
						imgUrl: "/static/images/My/AboutUs.png",
					},
				],
				agentStatus: 0
			};
		},
		computed: {
			userInfo() {
				return this.$store.state.userInfo
			},
			avatar() {
				return this.userInfo.avatar ||
					'https://hilton-duoladuo.oss-cn-shenzhen.aliyuncs.com/basic-common/upload/680ae589463da387fd39ef10.jpg'
			},
			nickname() {
				return this.userInfo.nickname
			},
			id() {
				return this.userInfo.id
			},
			telephone() {
				return this.userInfo.telephone
			},
			showGotoAgency() {
				return this.agentStatus === 0 || this.agentStatus === 1 || this.agentStatus === 3
			},
			showCommissionDetail() {
				return this.agentStatus === 2
			}
		},
		onShow() {
			this.getAgentInfo()
		},
		onLoad() {
			this.getCommissionTotalData()
		},
		methods: {
			maskPhoneNumber(phoneNumber) {
				// 确保输入是有效的电话号码
				if (phoneNumber.length !== 11 || isNaN(phoneNumber)) {
					return "Invalid phone number";
				}

				// 提取前3位和后4位
				const prefix = phoneNumber.slice(0, 3);
				const suffix = phoneNumber.slice(-4);

				// 生成中间的星号部分
				const maskedMiddle = '*'.repeat(phoneNumber.length - prefix.length - suffix.length);

				// 组合前后缀和中间的星号
				return `${prefix}${maskedMiddle}${suffix}`;
			},
			goto(item) {
				this.token = uni.getStorageSync("userToken")
				if (!this.token) {
					uni.showToast({
						icon: "error",
						title: '请先登录',
						duration: 1000,
						complete: () => {
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/index/HiltonHotelPage'
								})
							}, 1000)
						},
					})
					return
				}
				console.log("goto")

				if ("goToMyorder" == item) {
					uni.navigateTo({
						url: "/pages/AllOrderPage/AllOrderPage"
					})
				} else if ("gotoMycollection" == item) {
					uni.navigateTo({
						url: "/pages/MyCollectionPage/MyCollectionPage"
					})
				} else if ("goToAgency" == item) {
					uni.navigateTo({
						url: "/pages/AgentApplicationPage/AgentApplicationPage"
					})
				} else if ("goToShoppingAddress" == item) {
					uni.navigateTo({
						url: "/pages/addressManager/index"
					})
				} else if ("gotToMyPartnerPage" == item) {
					uni.navigateTo({
						url: "/pages/MyPartnerPage/MyPartnerPage"
					})
				} else if ("goToPointsDetails" == item) {
					uni.navigateTo({
						url: '/pages/PointsDetailsPage/PointsDetailsPage'
					})
				}
			},
			// goToMyorder() {
			// 	this.token = uni.getStorageSync("userToken")
			// 	if (!this.token) {
			// 		uni.showToast({
			// 			icon: "error",
			// 			title: '请先登录',
			// 			duration: 1000,
			// 			complete: () => {
			// 				setTimeout(() => {
			// 					uni.reLaunch({
			// 						url: '/pages/index/HiltonHotelPage'
			// 					})
			// 				}, 1000)
			// 			},
			// 		})
			// 		return
			// 	}
			// 	console.log("goto")
			// 	uni.navigateTo({
			// 		url: "/pages/AllOrderPage/AllOrderPage"
			// 	})
			// },
			// gotoMycollection() {
			// 	this.token = uni.getStorageSync("userToken")
			// 	if (!this.token) {
			// 		uni.showToast({
			// 			icon: "error",
			// 			title: '请先登录',
			// 			duration: 1000,
			// 			complete: () => {
			// 				setTimeout(() => {
			// 					uni.reLaunch({
			// 						url: '/pages/index/HiltonHotelPage'
			// 					})
			// 				}, 1000)
			// 			},
			// 		})
			// 		return
			// 	}
			// 	uni.navigateTo({
			// 		url: "/pages/MyCollectionPage/MyCollectionPage"
			// 	})
			// },
			// goToAgency() {
			// 	this.token = uni.getStorageSync("userToken")
			// 	if (!this.token) {
			// 		uni.showToast({
			// 			icon: "error",
			// 			title: '请先登录',
			// 			duration: 1000,
			// 			complete: () => {
			// 				setTimeout(() => {
			// 					uni.reLaunch({
			// 						url: '/pages/index/HiltonHotelPage'
			// 					})
			// 				}, 1000)
			// 			},
			// 		})
			// 		return
			// 	}
			// 	uni.navigateTo({
			// 		url: "/pages/AgentApplicationPage/AgentApplicationPage"
			// 	})
			// },
			goToCommissionDetail() {
				console.log("goto")
				uni.navigateTo({
					url: "/pages/CommissionDetailsPage/CommissionDetailsPage"
				})
			},
			// goToShoppingAddress() {
			// 	this.token = uni.getStorageSync("userToken")
			// 	if (!this.token) {
			// 		uni.showToast({
			// 			icon: "error",
			// 			title: '请先登录',
			// 			duration: 1000,
			// 			complete: () => {
			// 				setTimeout(() => {
			// 					uni.reLaunch({
			// 						url: '/pages/index/HiltonHotelPage'
			// 					})
			// 				}, 1000)
			// 			},
			// 		})
			// 		return
			// 	}
			// 	uni.navigateTo({
			// 		url: "/pages/addressManager/index"
			// 	})
			// },

			goToUserCenterPage() {
				uni.navigateTo({
					url: "/pages/UserCenterPage/UserCenterPage"
				})
			},
			// gotToMyPartnerPage() {
			// 	this.token = uni.getStorageSync("userToken")
			// 	if (!this.token) {
			// 		uni.showToast({
			// 			icon: "error",
			// 			title: '请先登录',
			// 			duration: 1000,
			// 			complete: () => {
			// 				setTimeout(() => {
			// 					uni.reLaunch({
			// 						url: '/pages/index/HiltonHotelPage'
			// 					})
			// 				}, 1000)
			// 			},
			// 		})
			// 		return
			// 	}

			// 	uni.navigateTo({
			// 		url: "/pages/MyPartnerPage/MyPartnerPage"
			// 	})
			// },
			navigateTo,
			async getCommissionTotalData() {
				try {
					const res = await getCommissionTotal()
					if (res && res.data) {
						this.totalCommission = res.data
					}
				} catch (err) {
					console.log('获取总分佣金额失败:', err)
				}
			},
			// goToPointsDetails() {
			// 	this.token = uni.getStorageSync("userToken")
			// 	if (!this.token) {
			// 		uni.showToast({
			// 			icon: "error",
			// 			title: '请先登录',
			// 			duration: 1000,
			// 			complete: () => {
			// 				setTimeout(() => {
			// 					uni.reLaunch({
			// 						url: '/pages/index/HiltonHotelPage'
			// 					})
			// 				}, 1000)
			// 			},
			// 		})
			// 		return
			// 	}
			// 	uni.navigateTo({
			// 		url: '/pages/PointsDetailsPage/PointsDetailsPage'
			// 	})
			// },
			async getAgentInfo() {
				try {
					const res = await getAgentInfo()
					if (res && res.data) {
						this.agentStatus = res.data.status
					}
				} catch (err) {
					console.log('获取代理状态:', err)
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	@import "../../static/commonStyleLess/grayBox.less";

	.my {
		// 公共样式
		letter-spacing: 0px;
		font-family: 'PingFang SC';
		color: #222222;
		letter-spacing: 0px;

		.text {
			font-weight: 400;
			font-size: 28rpx;
		}

		.button {
			width: 160rpx;
			height: 56rpx;
			border-radius: 8rpx;
			background: #0F4C97;
			font-weight: 400;
			font-size: 26rpx;
			line-height: 56rpx;
			text-align: center;
			letter-spacing: 0px;
			color: #FFFFFF;

		}

		.head {
			width: 750rpx;
			height: 200rpx;
			background: #0F4C97;
			padding-top: 20rpx;
			// border: 1px solid black;
			position: relative;

			.head_content {
				// width: 100%;
				margin-left: 30rpx;
				margin-top: 20rpx;
				align-items: center;
				padding-left: 20rpx;
				padding-right: 20rpx;

				.head_left {
					width: 100rpx;
					height: 100rpx;
					border-radius: 100%;
				}

				.head_right {
					margin-left: 20rpx;
					font-weight: 400;
					color: #FFFFFF;
					flex: 1;

					.hr_top {
						font-size: 28rpx;
					}

					.hr_bottom {
						font-size: 24rpx;
						margin-top: 16rpx;
					}
				}

			}

			.tabBar {
				position: absolute;
				width: 690rpx;
				height: 156rpx;
				top: 160rpx;
				left: 30rpx;
				border-radius: 16rpx;
				background: #FFFFFF;
				justify-content: center;

				.tbContent {
					width: 100%;

					.tb1,
					.tb2,
					.tb3 {
						justify-content: center;
						align-items: center;
					}

					.tb2,
					.tb3 {
						// margin-left: 132rpx;
					}

					.tbImg {
						width: 40rpx;
						height: 42rpx;
					}

					.tbText {
						font-weight: 400;
						font-size: 24rpx;
						letter-spacing: 0px;
						margin-top: 20rpx;
						width: 100%;

					}
				}

			}

		}

		.item {
			width: 690rpx;
			border-radius: 16rpx;
			padding: 30rpx 30rpx;
			align-items: center;
			background: #FFFFFF;
			margin: 20rpx auto 0 auto;
		}

		.one {
			margin: 136rpx auto 0 auto;
		}

		.two {
			.two_left {
				.tl_two {
					font-weight: 500;
					font-size: 28rpx;
					color: #FF4D00;

				}
			}
		}

		.learnMore {
			border-radius: 20rpx;

			.LMitem {
				// justify-content: center;
				align-items: center;

				.lm_left {
					align-items: center;

					image {
						width: 40rpx;
						height: 40rpx;
					}

					text {
						font-weight: 400;
						font-size: 28rpx;
						color: #222222;
						margin-left: 20rpx;
					}
				}

				.lm_right {
					width: 30rpx;
					height: 30rpx;
					flex: 1;
				}
			}
		}

		.second-item {
			margin-top: 70rpx;
			font-size: 30rpx;
		}
	}
</style>